var req;
	function refreshcaptcha()
	{
		// branch for native XMLHttpRequest object
		var url="create_captcha.jsp";
                url=url+"?tt="+new Date().getTime();
		if (window.XMLHttpRequest) {

			req = new XMLHttpRequest();
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send(null);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
				req.onreadystatechange = processReqChange;
				req.open("GET", url, true);
				req.send();
			}
		}
	}

	/*
	Ham (function) processReqChange la ham chiu trach nhiem chinh xu ly viec goi du lieu va nhan du lieu.
	Cac buoc ma ham nay thuc hien:
	1. Doi cho den khi may chu gui phan hoi thong bao la no da xu ly xong
	2. Doc thong bao tu may chu (may chu se gui status=200 nen xu ly thanh cong, 404 neu file khong tim thay,...).
	Neu may chu noi la xu ly thanh cong, tiep tuc buoc tiep theo
	3. Nhan du lieu ve duoi dang XML. Su dung DOM de phan tich du lieu XML.
	File XML nhan ve se cung cap cac thong tin:
		a) Ten ham goi ban dau (giua 2 the <method> va </method>)
		b) Gia tri thong bao ket qua thuc hien ham do (giua 2 the <result> va </result>)
	Biet duoc 2 thong tin tren, goi lai ham do (eval) voi gia tri tra ve de cap nhap giao dien
	Vi du, ham checkName() goi thong tin len may chu hoi, may chu tra ve ten ham la checkName va ket qua la 1. Ta se goi:
		checkName('',1);
	*/
	function processReqChange()
	{
		if (req.readyState == 4) // only if req shows "complete"
		{
			if (req.status == 200) // only if "OK"
			{
				document.getElementById("captcha1").innerHTML=req.responseText;
                                

			}
		}
	}





var req_checkregister;
	function checkregister11(str,str2,str3)
	{
		// branch for native XMLHttpRequest object
		var url="xuly_captcha.jsp";
			url=url+"?na="+str+"&user="+str2+"&email="+str3+"&tt="+new Date().getTime();
		if (window.XMLHttpRequest) {
			req_checkregister = new XMLHttpRequest();
			req_checkregister.onreadystatechange = processReqChange_checkregister;
			req_checkregister.open("GET", url, true);
			req_checkregister.send(null);
		// branch for IE/Windows ActiveX version
		} else if (window.ActiveXObject) {
			req_checkregister = new ActiveXObject("Microsoft.XMLHTTP");
			if (req_checkregister) {
				req_checkregister.onreadystatechange = processReqChange_checkregister;
				req_checkregister.open("GET", url, true);
				req_checkregister.send();
			}
		}
	}


	function processReqChange_checkregister()
	{
		if (req_checkregister.readyState == 4) // only if req shows "complete"
		{
			if (req_checkregister.status == 200) // only if "OK"
			{
				document.getElementById("tb").innerHTML="";
				document.getElementById("divpass").innerHTML="";
				document.getElementById("divusername").innerHTML="";
				document.getElementById("divfullname").innerHTML="";
				document.getElementById("divcfpass").innerHTML="";
				document.getElementById("divadress").innerHTML="";
				document.getElementById("divphone").innerHTML="";
				document.getElementById("divemail").innerHTML="";
                                var phonenumber = document.getElementById('PHONE').value;
				var email = document.getElementById('EMAIL').value;
					var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                                        var filterphone=/^(\()?\d{3}(\))?(-|\s)?\d{3}(-|\s)\d{4}$/;
				if(req_checkregister.responseText==1)
				{
					document.getElementById("tb").innerHTML="Security Code Error";
                                        
				if(document.getElementById("PassWord").value!=document.getElementById("cf_PassWord").value)
				 {
					 document.getElementById("divcfpass").innerHTML="Cormfirm pass Wrong";
					 document.getElementById("PassWord").value="";
					  document.getElementById("cf_PassWord").value="";
					  document.getElementById("PassWord").focus();

				 }
				 if(document.getElementById("UserName").value=="")
				 {
					 document.getElementById("divusername").innerHTML="Username Can not empty";

				 }

				 if(document.getElementById("PassWord").value=="")
				 {
					 document.getElementById("divpass").innerHTML="Pass Can not empty";

				 }

				 if(document.getElementById("fullname").value=="")
				 {
					 document.getElementById("divfullname").innerHTML="Full Can not empty";

				 }

				 if(document.getElementById("Address").value=="")
				 {
					 document.getElementById("divadress").innerHTML="Address Can not empty";

				 }

				 if(document.getElementById("PHONE").value=="")
				 {
					 document.getElementById("divphone").innerHTML="phone Can not empty";

				 }

				  if (!filter.test(email)) {
					  document.getElementById("divemail").innerHTML="Please provide a valid email address";
					


					}
					if (phonenumber != "") {
			if(!filterphone.test(phonenumber))
   			{
				document.getElementById("divphone").innerHTML="Format phone has six format: xxx-xxx-xxxx or (xxx)xxx-xxxx or xxx xxx xxxx or (xxx)xxx xxxx or xxx-xxx xxxx or xxx xxx-xxxx.";

   			}
			}
				}
				else if(req_checkregister.responseText==2)
				{
					document.getElementById("divusername").innerHTML="This User Used";
                                        
					
				if(document.getElementById("PassWord").value!=document.getElementById("cf_PassWord").value)
				 {
					 document.getElementById("divcfpass").innerHTML="Cormfirm pass Wrong";
					 document.getElementById("PassWord").value="";
					  document.getElementById("cf_PassWord").value="";
					  document.getElementById("PassWord").focus();

				 }
				 if(document.getElementById("UserName").value=="")
				 {
					 document.getElementById("divusername").innerHTML="Username Can not empty";

				 }

				 if(document.getElementById("PassWord").value=="")
				 {
					 document.getElementById("divpass").innerHTML="Pass Can not empty";

				 }

				 if(document.getElementById("fullname").value=="")
				 {
					 document.getElementById("divfullname").innerHTML="Full Can not empty";

				 }

				 if(document.getElementById("Address").value=="")
				 {
					 document.getElementById("divadress").innerHTML="Address Can not empty";

				 }

				 if(document.getElementById("PHONE").value=="")
				 {
					 document.getElementById("divphone").innerHTML="phone Can not empty";

				 }

				  if (!filter.test(email)) {
					  document.getElementById("divemail").innerHTML="Please provide a valid email address";
					


					}
					if (phonenumber != "") {
			if(!filterphone.test(phonenumber))
   			{
				document.getElementById("divphone").innerHTML="Format phone has four format: xxx-xxx-xxxx or (xxx)xxx-xxxx or xxx xxx xxxx or (xxx)xxx xxxx or xxx-xxx xxxx or xxx xxx-xxxx.";

   			}
			}
				}
				else if(req_checkregister.responseText==3)
				{
					document.getElementById("divemail").innerHTML="This Email Used";
                                        
					
				if(document.getElementById("PassWord").value!=document.getElementById("cf_PassWord").value)
				 {
					 document.getElementById("divcfpass").innerHTML="Cormfirm pass Wrong";
					 document.getElementById("PassWord").value="";
					  document.getElementById("cf_PassWord").value="";
					  document.getElementById("PassWord").focus();

				 }
				 if(document.getElementById("UserName").value=="")
				 {
					 document.getElementById("divusername").innerHTML="Username Can not empty";

				 }

				 if(document.getElementById("PassWord").value=="")
				 {
					 document.getElementById("divpass").innerHTML="Pass Can not empty";

				 }

				 if(document.getElementById("fullname").value=="")
				 {
					 document.getElementById("divfullname").innerHTML="Full Can not empty";

				 }

				 if(document.getElementById("Address").value=="")
				 {
					 document.getElementById("divadress").innerHTML="Address Can not empty";

				 }

				 if(document.getElementById("PHONE").value=="")
				 {
					 document.getElementById("divphone").innerHTML="phone Can not empty";

				 }

				  if (!filter.test(email)) {
					  document.getElementById("divemail").innerHTML="Please provide a valid email address";
					


					}
					if (phonenumber != "") {
			if(!filterphone.test(phonenumber))
   			{
				document.getElementById("divphone").innerHTML="Format phone has four format: xxx-xxx-xxxx or (xxx)xxx-xxxx or xxx xxx xxxx or (xxx)xxx xxxx or xxx-xxx xxxx or xxx xxx-xxxx.";

   			}
			}
				}
				else 
				{
					
					
				if(document.getElementById("PassWord").value!=document.getElementById("cf_PassWord").value)
				 {
					 document.getElementById("divcfpass").innerHTML="Cormfirm pass Wrong";
					 document.getElementById("PassWord").value="";
					  document.getElementById("cf_PassWord").value="";
					  document.getElementById("PassWord").focus();

				 }
				 if(document.getElementById("UserName").value=="")
				 {
					 document.getElementById("divusername").innerHTML="Username Can not empty";

				 }

				 if(document.getElementById("PassWord").value=="")
				 {
					 document.getElementById("divpass").innerHTML="Pass Can not empty";

				 }

				 if(document.getElementById("fullname").value=="")
				 {
					 document.getElementById("divfullname").innerHTML="Full Can not empty";

				 }

				 if(document.getElementById("Address").value=="")
				 {
					 document.getElementById("divadress").innerHTML="Address Can not empty";

				 }

				 if(document.getElementById("PHONE").value=="")
				 {
					 document.getElementById("divphone").innerHTML="phone Can not empty";

				 }

				  if (!filter.test(email)) {
					  document.getElementById("divemail").innerHTML="Please provide a valid email address";
					


					}
					if (phonenumber != "") {
			if(!filterphone.test(phonenumber))
   			{
				document.getElementById("divphone").innerHTML="Format phone has four format: xxx-xxx-xxxx or (xxx)xxx-xxxx or xxx xxx xxxx or (xxx)xxx xxxx or xxx-xxx xxxx or xxx xxx-xxxx.";

   			}
			}
				if(document.getElementById("PassWord").value!=document.getElementById("cf_PassWord").value||
                                    document.getElementById("UserName").value==""||
                                    document.getElementById("PassWord").value==""||
                                    document.getElementById("fullname").value==""||
                                    document.getElementById("Address").value==""||
                                    document.getElementById("PHONE").value==""||
                                    !filter.test(email)||
                                    !filterphone.test(phonenumber))
				{
					return;
				}
				 document.getElementById("frm1").submit();
				}

			}
		}
	}
	